package com.hc.summary.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.hc.annotations.BindView;
import com.hc.summary.R;
import com.hc.summary.annotation.IBindViewTool;
import com.hc.summary.dagger2.bean.DatabaseObject;
import com.hc.summary.dagger2.bean.NetObject;
//import com.hc.summary.dagger2.component.DaggerComponentOne;
import com.hc.summary.hilt.annotation.BindTestOne;
import com.hc.summary.hilt.annotation.BindTestTwo;
import com.hc.summary.hilt.bean.TestBean;
import com.hc.summary.hilt.bean.TestInterface;
import com.hc.summary.hilt.bean.TestInterfaceBeanOne;
import com.hc.summary.retrofit.BaiduInterface;

import java.io.IOException;

import javax.inject.Inject;

import dagger.hilt.android.AndroidEntryPoint;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

@AndroidEntryPoint
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @BindView(R.id.tv_tv1)
    TextView tv_tv1;
    @BindView(R.id.tv_tv2)
    TextView tv_tv2;
//    @Inject
    NetObject netObject;
//    @Inject
    DatabaseObject databaseObject;
    @Inject
    TestBean testBean;
    @BindTestTwo
    @Inject
    TestInterface testInterface;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        DaggerComponentOne.create().injectMainActivity(this);
//        DaggerComponentOne.builder()
//                .netModule(new NetModule())
//                .databaseModule(new DatabaseModule())
//                .build()
//                .injectMainActivity(this);
        Log.d(TAG,testBean.hashCode()+"testBean");
        Log.d(TAG, testInterface.hashCode()+"testInterfaceBean");
        testInterface.method();
        IBindViewTool.bindviews(this);
        tv_tv1.setText("Hello World");
        tv_tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                request();
            }
        });
    }

    private void request(){
        Retrofit retrofit = new Retrofit.Builder().baseUrl("https://www.baidu.com").build();
        BaiduInterface baiduInterface = retrofit.create(BaiduInterface.class);
        Call<ResponseBody> call = baiduInterface.requestBaidu();
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    Log.i(TAG,response.body().string());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {

            }
        });
    }

} 